import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		isSubscribe: uni.getStorageSync('isSubscribe') || false,
		mpMessagePush: uni.getStorageSync('mpMessagePush') || false,
		token: uni.getStorageSync('token') || '',
		userInfo: uni.getStorageSync('userInfo') || {},
		isLogin: uni.getStorageSync('token') ? true : false,
		staffListAll: [],
		petInfo: uni.getStorageSync('petInfo') || null,
		// staffListAll:uni.getStorageSync('staffListAll') || [],
	},
	mutations: {
		SET_MSGPUSH(state, data) {
			uni.setStorageSync(
				'mpMessagePush', data
			)
			state.mpMessagePush = data
		},
		SET_isSubscribe(state, data) {
			uni.setStorageSync(
				'isSubscribe', data
			)
			state.isSubscribe = data
		},
		SET_PET(state, data) {
			uni.setStorageSync(
				'petInfo', data
			)
			state.petInfo = data
		},
		SET_TOKEN(state, data) {
			uni.setStorageSync(
				'token', data
			)
			console.log('----token-----', data);
			state.isLogin = data ? true : false
			state.token = data
		},
		SET_USERINFO(state, info) {
			uni.setStorageSync('userInfo', info)
			state.userInfo = info
		},
		SET_STAFFLIST(state, data) {
			// uni.setStorageSync('staffListAll', data)
			state.staffListAll = data
		},
	},
	actions: {
		setPetInfo({
			commit
		}, data) {
			commit("SET_PET", data);
		},
		setIsSubscribe({
			commit
		}, data) {
			commit("SET_isSubscribe", data);
		},
		setMsgPush({
			commit
		}, data) {
			commit("SET_MSGPUSH", data);
		},
		setUserinfo({
			commit
		}, data) {
			commit("SET_USERINFO", data);
		},
		setToken({
			commit
		}, data) {
			commit("SET_TOKEN", data);
		},
		setStafflistAll({
			commit
		}, data) {
			commit("SET_STAFFLIST", data);
		},
	},
	getters: {
		getToken: state => {
			return state.token
		}
	}
})

export default store
